package com.ykdl.member.views;

import java.util.ArrayList;
import java.util.Hashtable;

import android.content.Context;
import android.content.Intent;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.Toast;

import com.ykdl.member.kid.R;
import com.ykdl.member.constant.KidConfig;
import com.ykdl.member.kid.beans.ImageBean;
import com.ykdl.member.kid.gears.BaseScreen;
import com.ykdl.member.kid.util.CameraHelp;
/**
 * 
 * 发帖子页面的工具条
 *
 * @since 1.0
 */
public class SelectToolDataView extends LinearLayout implements OnClickListener {
	final public static int SHARE_CODE = 1983;
	public static CameraHelp mCameraHelp;
	private BaseScreen mActivity ;
	private Context context;
	private boolean needzoom= false;
	View tools;
	private EditText text;
	private boolean isopen = false;
	Hashtable<String, Integer> count = new Hashtable<String, Integer>();
	View open;
	private LinearLayout is_anonymous_ll ;
	private CheckBox is_anonymous ;
	private int max_photos=4;
	private boolean toolseanble=true;
	private int outputX=200;
	private int outputY=200;
	private ArrayList<ImageBean> photopath = new ArrayList<ImageBean>();
	private ImageView seltool_keybaord ;
	public void setMax_photos(int max_photos) {
		this.max_photos = max_photos;
	}
	public void setOwerActivity(BaseScreen mActivity) {
		this.mActivity = mActivity;
	}
	public SelectToolDataView(Context context) {
		super(context);
		this.context = context;
		init();
	}

	private void init() {
		View view = ((LayoutInflater) context
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(
				R.layout.select_tooldata, null);
		addView(view, new LayoutParams(LayoutParams.FILL_PARENT,
				LayoutParams.FILL_PARENT, 1));
		seltool_keybaord = (ImageView)findViewById(R.id.seltool_keybaord);
		findViewById(R.id.seltool_keybaord).setOnClickListener(this);
		findViewById(R.id.seltool_tackphone).setOnClickListener(this);
		findViewById(R.id.seltool_slephone).setOnClickListener(this);
		is_anonymous_ll =(LinearLayout) findViewById(R.id.is_anonymous_ll);
		is_anonymous  =(CheckBox) findViewById(R.id.is_anonymous);
	}

	public SelectToolDataView(Context context, AttributeSet attrs) {
		super(context, attrs);
		this.context = context;
		init();
	}

	public void setDataCount(String key, int pcount) {
		count.put(key, pcount);
	}
	public void setPhotoList(ArrayList<ImageBean> photopath) {
		this.photopath = photopath;
	}
	public void setCheckBoxGon() {
		is_anonymous_ll.setVisibility(View.GONE);
	}
	public boolean getCheckBoxIsCheck() {
		if (is_anonymous.isChecked()) {
			return true;
		}else {
			return false;
		}
		
		
	}
	public void setKeyBoardState(boolean pisopen) {
		isopen = pisopen;
	}
	public boolean getKeyBoardState() {
		return isopen ;
	}


	public void setEditText(EditText ptext,View tools) {
		text = ptext;
		this.tools =tools ;
	}
	

	@Override
	public void onClick(View v) {
		Intent t = null;
		int id = v.getId();

		switch (id) {
		
		case R.id.seltool_keybaord:

			if (isopen) {
				mActivity.hideKeyBorad(text);
				showToolView();
			} else {
				text.requestFocus();
				mActivity.showKeyBorad(text);
				hideToolView();
			}
			isopen = !isopen;
			break;
		case R.id.seltool_tackphone:
			if (photopath.size()==max_photos) {
				Toast.makeText(context, "只限"+max_photos+"张，请删除图片", Toast.LENGTH_LONG)
				.show();
			}else {
				
//				mActivity.hideKeyBorad(text);
				mCameraHelp = new CameraHelp(mActivity);
				mCameraHelp.selectImageFromCamera();
			}
			
			break;

		case R.id.seltool_slephone:
			if (photopath.size()==max_photos) {
				Toast.makeText(context, "只限"+max_photos+"张，请删除图片", Toast.LENGTH_LONG)
				.show();
			}else {
				mCameraHelp = new CameraHelp(mActivity);
				mCameraHelp.selectImageFromLocal();
			}
			break;


		}

	}



	public String setPicture(int requestCode, int resultCode, Intent data) {
		if(mCameraHelp==null){
			mCameraHelp = new CameraHelp(mActivity);
		}
		return mCameraHelp.setPicture(requestCode, resultCode, data);

	}
	
	

	public void hideToolView() {
		tools.setVisibility(View.GONE);
	}
	public void showToolView() {
		tools.setVisibility(View.VISIBLE);
	}

}